// Class1.cs
//

using System;
using System.DHTML;
using Sys;
using SBT;
using System.Silverlight;
using System.Silverlight.Presentation;

namespace Scripts04
{

    public class ScrollMgr : SLManager
    {
        public ScrollMgr(DOMElement host)
            : base(host)
        { }

        public override void OnSilverlightLoaded(System.Silverlight.SilverlightControl slControl, object args)
        {
            Downloader downloader = (Downloader)slControl.CreateObject("downloader");
            downloader.AddEventListener(DownloaderEvent.Completed, (Sys.EventHandler)delegate
            {
                SilverlightControl plugin = slControl;
                ControlContent content = plugin.Content;
                ComposedScroller globalScroller = new ComposedScroller();

                string downTpl = downloader.GetResponseText("ButtonDown.xaml");
                string upTpl = downloader.GetResponseText("ButtonUp.xaml");
                string enterTpl = downloader.GetResponseText("ButtonEnter.xaml");
                string leaveTpl = downloader.GetResponseText("ButtonLeave.xaml");

                Button left = new Button();
                left.Plugin = plugin;
                left.Element = (UIElement)content.FindName("btnLeft");
                left.MouseDownTemplate = downTpl;
                left.MouseEnterTemplate = enterTpl;
                left.MouseLeaveTemplate = leaveTpl;
                left.MouseUpTemplate = upTpl;
                left.Initialize();

                Button leftPage = new Button();
                leftPage.Plugin = plugin;
                leftPage.Element = (UIElement)content.FindName("pageLeft");
                leftPage.MouseDownTemplate = downTpl;
                leftPage.MouseEnterTemplate = enterTpl;
                leftPage.MouseLeaveTemplate = leaveTpl;
                leftPage.MouseUpTemplate = upTpl;
                leftPage.Initialize();

                Button right = new Button();
                right.Plugin = plugin;
                right.Element = (UIElement)content.FindName("btnRight");
                right.MouseDownTemplate = downTpl;
                right.MouseEnterTemplate = enterTpl;
                right.MouseLeaveTemplate = leaveTpl;
                right.MouseUpTemplate = upTpl;
                right.Initialize();

                Button rightPage = new Button();
                rightPage.Plugin = plugin;
                rightPage.Element = (UIElement)content.FindName("pageRight");
                rightPage.MouseDownTemplate = downTpl;
                rightPage.MouseEnterTemplate = enterTpl;
                rightPage.MouseLeaveTemplate = leaveTpl;
                rightPage.MouseUpTemplate = upTpl;
                rightPage.Initialize();

                Button top = new Button();
                top.Plugin = plugin;
                top.Element = (UIElement)content.FindName("btnUp");
                top.MouseDownTemplate = downTpl;
                top.MouseEnterTemplate = enterTpl;
                top.MouseLeaveTemplate = leaveTpl;
                top.MouseUpTemplate = upTpl;
                top.Initialize();

                Button topPage = new Button();
                topPage.Plugin = plugin;
                topPage.Element = (UIElement)content.FindName("pageUp");
                topPage.MouseDownTemplate = downTpl;
                topPage.MouseEnterTemplate = enterTpl;
                topPage.MouseLeaveTemplate = leaveTpl;
                topPage.MouseUpTemplate = upTpl;
                topPage.Initialize();

                Button bottom = new Button();
                bottom.Plugin = plugin;
                bottom.Element = (UIElement)content.FindName("btnDown");
                bottom.MouseDownTemplate = downTpl;
                bottom.MouseEnterTemplate = enterTpl;
                bottom.MouseLeaveTemplate = leaveTpl;
                bottom.MouseUpTemplate = upTpl;
                bottom.Initialize();

                Button bottomPage = new Button();
                bottomPage.Plugin = plugin;
                bottomPage.Element = (UIElement)content.FindName("pageDown");
                bottomPage.MouseDownTemplate = downTpl;
                bottomPage.MouseEnterTemplate = enterTpl;
                bottomPage.MouseLeaveTemplate = leaveTpl;
                bottomPage.MouseUpTemplate = upTpl;
                bottomPage.Initialize();

                Button bottomBar = new Button();
                bottomBar.Plugin = plugin;
                bottomBar.Element = (UIElement)content.FindName("bottomBar");
                bottomBar.MouseDownTemplate = downTpl;
                bottomBar.MouseEnterTemplate = enterTpl;
                bottomBar.MouseLeaveTemplate = leaveTpl;
                bottomBar.MouseUpTemplate = upTpl;
                bottomBar.Initialize();

                Grid bottomBar_grid = new Grid();
                bottomBar_grid.Plugin = plugin;
                bottomBar_grid.Element = (UIElement)content.FindName("bottomBar");
                bottomBar_grid.Initialize();

          

                Grid bottomGrid = new Grid();
                bottomGrid.Plugin = plugin;
                bottomGrid.Element = (UIElement)content.FindName("bottomGrid");
                bottomGrid.Initialize();

                Button rightBar = new Button();
                rightBar.Plugin = plugin;
                rightBar.Element = (UIElement)content.FindName("rightBar");
                rightBar.MouseDownTemplate = downTpl;
                rightBar.MouseEnterTemplate = enterTpl;
                rightBar.MouseLeaveTemplate = leaveTpl;
                rightBar.MouseUpTemplate = upTpl;
                rightBar.Initialize();

                Grid rightBar_grid = new Grid();
                rightBar_grid.Plugin = plugin;
                rightBar_grid.Element = (UIElement)content.FindName("rightBar");
                rightBar_grid.Initialize();

                Grid rightGrid = new Grid();
                rightGrid.Plugin = plugin;
                rightGrid.Element = (UIElement)content.FindName("rightGrid");
                rightGrid.Initialize();

                HorizontalScrollBar horScroll = new HorizontalScrollBar();
                horScroll.MinusBtn = left;
                horScroll.PlusBtn = right;
                horScroll.Bar = bottomBar;
                horScroll.BarContainer = bottomGrid;

                VerticalScrollBar verScroll = new VerticalScrollBar();
                verScroll.MinusBtn = top;
                verScroll.PlusBtn = bottom;
                verScroll.Bar = rightBar;
                verScroll.BarContainer = rightGrid;

                HorizontalPageFlipScroller horScrollPage = new HorizontalPageFlipScroller();
                horScrollPage.LeftButton = leftPage;
                horScrollPage.RightButton = rightPage;

                VerticalPageFlipScroller verScrollPage = new VerticalPageFlipScroller();
                verScrollPage.TopButton = topPage;
                verScrollPage.BottomButton = bottomPage;

                globalScroller.Scrollers = new IScroller[] { horScroll, verScroll, horScrollPage, verScrollPage };
                AgBehavior scrollContent = new AgBehavior();
                scrollContent.Plugin = plugin;
                scrollContent.Element = (UIElement)content.FindName("scrollContent");
                scrollContent.Initialize();

                ScrollContainer scrollContainer = new ScrollContainer();
                scrollContainer.Plugin = plugin;
                scrollContainer.Element = (UIElement)content.FindName("scrollContainer");
                scrollContainer.Content = scrollContent;
                scrollContainer.Scroller = globalScroller;
                scrollContainer.Initialize();
            });
            downloader.Open("GET", "Templates.zip");
            downloader.Send();
        }
    }
}
